package leetcode;

import java.util.Arrays;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2559.java
 * @Author : WangRuoyu
 * @Date 2023/2/22 9:18
 */
public class Q2559 {
    public int[] vowelStrings(String[] words, int[][] queries) {
        int[] res = new int[queries.length];
        int[] an = new int[words.length];
        int[] sn = new int[words.length + 1];

        for (int i = 0; i < words.length; ++i) {
            String word = words[i];
            if (((word.charAt(0) == 'a') || (word.charAt(0) == 'e') || (word.charAt(0) == 'i') || (word.charAt(0) == 'o') || (word.charAt(0) == 'u')) && ((word.charAt(word.length() - 1) == 'a') || (word.charAt(word.length() - 1) == 'e') || (word.charAt(word.length() - 1) == 'i') || (word.charAt(word.length() - 1) == 'o') || (word.charAt(word.length() - 1) == 'u'))) {
                an[i] = 1;
            }
        }

        for (int i = 1; i <= words.length; ++i) {
            sn[i] = sn[i - 1] + an[i - 1];
        }

        for (int i = 0; i < queries.length; ++i) {
            res[i] = sn[queries[i][1] + 1] - sn[queries[i][0]];
        }

        return res;
    }

    public static void main(String[] args) {
        Q2559 sl = new Q2559();
        String[] words = {"aba", "bcb", "ece", "aa", "e"};
        int[][] queries = {{0, 2}, {1, 4}, {1, 1}};
        System.out.println(Arrays.toString(sl.vowelStrings(words, queries)));
    }
}